###This file is broken down into subcomponents. Try each one out in the console before you finish and save this file.
###make sure that this file is the completed product.

###PART 1
##you might need to be in the correct directory
setwd('')
#read in the wine file again
wine <- read.csv('testWine.csv')
#cast the wine file from a data.frame to a matrix:
wine <- as.matrix(wine)


###PART 2
#use the summary() function to learn about the data
	#NOTE: notice how this does not print to the console when you source() this file (i.e., source('R_HW_2.R') )
	#you will need to also use the print() function for things that need to be printed, when using source()
##ANSWER HERE
#summary(wine)
print(summary(wine))

###PART 3
#use the cor() function to find the correlation between all the columns in the wine table
##ANSWER HERE
#cor(wine)
print(cor(wine))

###PART 4
#if you want to see just the first column of the data table, you do this:
print(wine[,1])
#if you want to see just the first row of the data table, you do this:
print(wine[1,])


#for the following parts, be sure to save each mean, standard deviation, and length into variables
###PART 5
#use the mean function ( mean() ) to find:
##ANSWER HERE
wine.mean <- mean(wine)
print(wine.mean)

#use the mean, standard deviation, and length functions (mean(), sd(), and length() respectively) to find:
	#the mean, sd, and length of each row of the wine table (there are 6 rows)

##ANSWER HERE
wine.1.mean <- mean(wine[1,])
print(wine.1.mean)

wine.2.mean <- mean(wine[2,])
print(wine.2.mean)

wine.3.mean <- mean(wine[3,])
print(wine.3.mean)

wine.4.mean <- mean(wine[4,])
print(wine.4.mean)

wine.5.mean <- mean(wine[5,])
print(wine.5.mean)

wine.6.mean <- mean(wine[6,])
print(wine.6.mean)


wine.1.sd <- sd(wine[1,])
print(wine.1.sd)

wine.2.sd <- sd(wine[2,])
print(wine.2.sd)

wine.3.sd <- sd(wine[3,])
print(wine.3.sd)

wine.4.sd <- sd(wine[4,])
print(wine.4.sd)

wine.5.sd <- sd(wine[5,])
print(wine.5.sd)

wine.6.sd <- sd(wine[6,])
print(wine.6.sd)


wine.1.length <- length(wine[1,])
print(wine.1.length)

wine.2.length <- length(wine[2,])
print(wine.2.length)

wine.3.length <- length(wine[3,])
print(wine.3.length)

wine.4.length <- length(wine[4,])
print(wine.4.length)

wine.5.length <- length(wine[5,])
print(wine.5.length)

wine.6.length <- length(wine[6,])
print(wine.6.length)


###PART 6
#compute the t-statistic for each of the rows with what you have above. The population mean will be the mean of the table.
	#you will also need the square root function ( sqrt() )
#the t-statistic for the first row should look something like the following line (feel free to condense it):
##ANSWER HERE

t.1.numerator <- wine.1.mean - wine.mean
t.1.denominator <- wine.1.sd * sqrt(wine.1.length)
t.1 <- t.1.numerator/t.1.denominator

t.2.numerator <- wine.2.mean - wine.mean
t.2.denominator <- wine.2.sd * sqrt(wine.2.length)
t.2 <- t.2.numerator/t.2.denominator

t.3.numerator <- wine.3.mean - wine.mean
t.3.denominator <- wine.3.sd * sqrt(wine.3.length)
t.3 <- t.3.numerator/t.3.denominator

t.4.numerator <- wine.4.mean - wine.mean
t.4.denominator <- wine.4.sd * sqrt(wine.4.length)
t.4 <- t.4.numerator/t.4.denominator

t.5.numerator <- wine.5.mean - wine.mean
t.5.denominator <- wine.5.sd * sqrt(wine.5.length)
t.5 <- t.5.numerator/t.5.denominator

t.6.numerator <- wine.6.mean - wine.mean
t.6.denominator <- wine.6.sd * sqrt(wine.6.length)
t.6 <- t.6.numerator/t.6.denominator


###PART 7
##the final product of this script should print (i.e., use the print() function), in series, the t-statistic for each row compared to the table mean.
##ANSWER HERE
print(t.1)

print(t.2)

print(t.3)

print(t.4)

print(t.5)

print(t.6)

